<?php
//导航条控制器
class NavController extends Controller {
    public function __construct() {
        parent::__construct();
        $this->viewFolder = 'nav/';
    }
    //导航条列表
    public function index() {
        parent::page(10);
        if(isset($_GET['pid']))
        $this->tpl->assign('oneNav',$this->model->findOne());
        $this->tpl->assign('allNav',$this->model->findAll());
        $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'nav_list.tpl');
    }

    //添加导航
    public function add() {
        $this->tpl->assign('allParentNav',Tool::setFormItem($this->model->findAllParentNavNoPage(),'id','nav_name'));
        $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'add.tpl');
    }
    /*
    //添加子导航
    public function addsub() {
        if(isset($_GET['id'])){
            $this->tpl->assign('oneNav',$this->model->findOne());
            $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'addsub.tpl');
        }
    }
    */
    public function addSubmit() {
        if(isset($_POST['add'])){
            echo $this->model->add() ? 'success' : 'failed';
        }
    }
    //ajax方式判断
    public function isOneByAjax() {
        if(!empty($_GET)){
            echo $this->model->isOneByAjax() ? 'false' : 'true';
        }
    }
    public function del() {
        if(isset($_GET['id'])){
            echo $this->model->del() ? 'success' : 'failed';
        }
    }
    public function update() {
        if(isset($_GET['id'])){
            $this->tpl->assign('oneNav',$this->model->findOne());
            $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'pop_update_nav.tpl');
        }
    }
    public function updateSubmit() {
        if(isset($_GET['id'])){
            if($this->model->update() !== false){
                echo 'success';
            }
        }
    }
    public function sort() {
        if(isset($_POST['update'])){
            if($this->model->sort() !== false){
                echo 'success';
            }
        }
    }
}